<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="CSS/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">合同版本设置 - ${version == null ? "添加" : "修改"}</h1>

<div class="container_12 clearfix leading">

    

    <div class="side grid_12 leading">
        <form class="form has-validation" name="post_form" id="post_form">
            <div class="clear"></div>
            <div class="clearfix">
                <label for="name_input" class="form-label">名称 <em>*</em></label>
                <div class="form-input"><input type="text" id="name_input" name="version.contractName" value="${version.contractName}" required="required" placeholder="请输入版本名称"/></div>
            </div>

            <div class="clearfix">
                <label for="version_input" class="form-label">版本 <em>*</em></label>
                <div class="form-input">
                    <input type="text" id="version_input" name="version.contractVer" value="${version.contractVer}" required="required" placeholder="请输入版本号"/>
                </div>
            </div>

            <div class="clearfix">
                <label for="org_sel" class="form-label">公司名称</label>
                <div class="form-input">
                    <select id="org_sel" name="version.organization.id">
                        <s:iterator value="#request.organizations" var="org" status="st">
                            <s:if test="#st.index == 0 && #request.organizationId < 0">
                                <option value="${org.id}" selected="selected">${org.fullName}</option>
                            </s:if>
                            <s:elseif test="#request.organizationId == #org.id">
                                <option value="${org.id}" selected="selected">${org.fullName}</option>
                            </s:elseif>
                            <s:else>
                                <option value="${org.id}">${org.fullName}</option>
                            </s:else>
                        </s:iterator>
                    </select>
                </div>

                <div class="clearfix">
                    <label for="template_sel" class="form-label">合同模板 <em>*</em></label>
                    <div class="form-input">
                        <select id="template_sel" name="version.contractTemplate" style="opacity: 0;">
                            <option value="contract_template1">厦门公司合同</option>
                            <option value="contract_template2">漳州分公司合同</option>
                            <option value="contract_template3">厦门乔盛服装饰品有限公司退休人员合同</option>
                            <option value="contract_template4">漳州通茂服装饰品有限公司退休人员合同</option>
                        </select>
                    </div>
                </div>

                <div class="clearfix"></div>

            </div>
            <div class="form-action clearfix">
                <s:if test="#request.version != null and #request.version.id != null">
                <input type="hidden" name="version.id" value="${version.id}"/>
                </s:if>
                
                <button class="button" type="button" onclick="checkForm()">${version == null ? "添加" : "修改"}</button>
                <button class="button" type="button" onclick="resetForm()">重置</button>
                <a class="button" href="#contract/version.xhtml?operation=set"><span style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>


<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
    $(function(){
        
        $("#template_sel").val("${version.contractTemplate}");
    });
    function checkForm() {
        if (checkNull($("#name_input").attr("value"))) {
            alert("名称不为空");
            return false;
        }
        if (checkNull($("#version_input").attr("value"))) {
            alert("版本描述不为空");
            return false;
        }

        var url = "${ctx}/contract/version_save.xhtml";
        $.ajax(url, {
            type: "POST",
            data: $("#post_form").serialize(),
            dataType:"html",
            cache:false,
            success:function(a) {
                return pageDownloaded(a, url)
            },
            complete:function() {
            }
        });
    }
    function resetForm() {
        $("#name_input").attr("value", "");
        $("#version_input").attr("value", "");
    }
</script>
    